package br.com.trumah.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.trumah.dao.interfaces.DoadorJuridicoDAO;
import br.com.trumah.model.DoadorJuridico;
import br.com.trumah.utils.HibernateUtil;

public class DoadorJuridicoDAOImpl implements DoadorJuridicoDAO {

	@Override
	public void salvar(DoadorJuridico doadorJuridico) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.save(doadorJuridico);
		t.commit();
	}

	@Override
	public DoadorJuridico obterDoadorJuridico(long id) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (DoadorJuridico) session.load(DoadorJuridico.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DoadorJuridico> listar() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		List<DoadorJuridico> lista = session.createQuery("from DoadorJuridico").list();
		t.commit();
		return lista;
	}

	@Override
	public void remover(DoadorJuridico doadorJuridico) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.delete(doadorJuridico);
		t.commit();
	}

	@Override
	public void atualizar(DoadorJuridico doadorJuridico) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.update(doadorJuridico);
		t.commit();
	}

}
